package com.yusheng.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 工具类主要用来和jdbc进行连接，封装数据库连接和释放操作
 *
 */
public class JdbcUtil {


    public Connection connection=null;
    public Connection connection1=null;
    public PreparedStatement preparedStatement=null;
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {

    }
    public void getConnection() throws SQLException {

        connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/datayusheng","root","423125");

    }
    public void getConnection1() throws SQLException {

        connection1=DriverManager.getConnection("jdbc:mysql://localhost:3306/datayusheng","root","423125");

    }
    public void close(){
        if (preparedStatement!=null) {
            try {
                preparedStatement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (connection!=null) {
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
    public void close1(){
        if (preparedStatement!=null) {
            try {
                preparedStatement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (connection1!=null) {
            try {
                connection1.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
}
